if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.groups.AddUsers")) {
    jsx3.require("jsx3.gui.Dialog")
    /**
     *
     */
    jsx3.lang.Package.definePackage("tibco.admin.enterpriseAssets.userMgt.groups", function (addUsers) {
    });

    /**
     *
     */
    jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.userMgt.groups.AddUsers",
            jsx3.gui.Dialog,
            null,
            function (addUsers) {

				/**
				 * instance initializer
				 */
                addUsers.prototype.initialize = function() {
                    // set the window instance id
                    if (jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.window.Window")) {
                        this.window = this.getAncestorOfType(tibco.admin.enterpriseAssets.userMgt.window.Window)
                        if (this.window) {
                            this.setWindowId(this.window.getId());
                        }
                    }
                    // set the matrix
                    this.userRsList = this.getDescendantOfName("mtxSearchRs_24_J_2");
                    this.mtxUsersAdd = this.getDescendantOfName("mtxAddUsers_24_J_2");
                    this.searchBtn = this.getDescendantOfName("btnSearch_24_J_2");
                    this.saveBtn = this.getDescendantOfName("btnSaveUser_24_J_2");
                    var curMe = this;
                    this.searchBtn.callsearchUsers = function() {
                        curMe.callsearchUsers();
                    }
                    this.mtxUsersAdd.onDelete = function(recordId) {
                        curMe.onDelete(recordId);
                    }
                    this.saveBtn.calladdUsersToGroup = function() {
                        curMe.calladdUsersToGroup();
                    }
                    this.groupId = "";
                    this.groupName = "";
                    //if (jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.window.Window")) {
                    //    this.container = this.getAncestorOfType("tibco.admin.enterpriseAssets.userMgt.window.Window");
                    //    if (this.container) {
                    //        var groupDetailObj = this.container.getDescendantsOfType("tibco.admin.enterpriseAssets.userMgt.groups.GroupDetail")[0];
                    //        this.groupId = groupDetailObj.groupId;
                    //        this.groupName = groupDetailObj.groupName;
                    //    }
                    //}
                    this.getDescendantOfName("lblGroupName_24_J_2").setText(this.groupName);

                }

               // set the window instance
                addUsers.prototype.setWindow = function(window) {
                    this.container = window
                    var groupDetailObj = this.container.getDescendantsOfType("tibco.admin.enterpriseAssets.userMgt.groups.GroupDetail")[0];
                    this.groupId = groupDetailObj.groupId;
                    this.groupName = groupDetailObj.groupName;
					this.getDescendantOfName("windowBar").setText(
							tibco.admin.Main.getServer().getDynamicProperty("@@titleAddUsers_24_J_2", this.groupName), true);
                }

                /**
				 *   set the current window ID
				 *   @para strId {string} The window id
				 */
                addUsers.prototype.setWindowId = function(strId) {
                    this.windowId = strId
                }

                /**
				 *   get the current window ID
				 *   @return {string} The window id
				 */
                addUsers.prototype.getWindowId = function() {
                    return this.windowId
                }


                /**
                 *	 Delete the current record in group added list and add the delete record into the search result list
				 *  @para recordId {string} The id of the record to be deleted.
                 */
                addUsers.prototype.onDelete = function(recordId) {
                    var transRecord = this.mtxUsersAdd.getRecordNode(recordId);
                    this.mtxUsersAdd.deleteRecord(recordId, true);
                    try
                    {
                        this.userRsList.insertRecordNode(transRecord, "jsxroot", true);
                        this.mtxUsersAdd.repaint();
                    }
                    catch (ex)
                    {
                        tibco.admin.Main.logException(ex, "Error in tibco.admin.enterpriseAssets.userMgt.user.AddGroups.onDelete");
                    }
                }





                //==================== do search users ============================
                /**
				 *	  Search users - webservice call
				 */
                addUsers.prototype.callsearchUsers = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/groups/rules/searchUsers.xml", "searchUsers", "Search Users");

                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onsearchUsersSuccess);
                    //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.onsearchUsersError);
                    //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.onsearchUsersInvalid);
					objService.searchLimit = 500;
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                    objService.doCall();
                };

                addUsers.prototype.onsearchUsersSuccess = function(objEvent) {
                    var sourceXML = objEvent.target.getInboundDocument();
                    this.userRsList.setSourceXML(sourceXML);
                    this.userRsList.repaint();
                };

                addUsers.prototype.onsearchUsersError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                };

                addUsers.prototype.onsearchUsersInvalid = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };


                //================== do save the users ====================
                 /**
				 *	  Add users to group - webservice call
				 */
                addUsers.prototype.calladdUsersToGroup = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/groups/rules/addUsersToGroup.xml", "addUsersToGroup", "Add users to group");

                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onaddUsersToGroupSuccess);
                    //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.onaddUsersToGroupError);
                    //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.onaddUsersToGroupInvalid);
                    objService.groupId = this.groupId;
                    objService.groupName = this.groupName;
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                    objService.doCall();
                };

                addUsers.prototype.onaddUsersToGroupSuccess = function(objEvent) {
                    if (objEvent.target.simpleActionResponse == "true") {
                        this.publishRefresh();
                        this.doClose();
                    }
                    else {
                        tibco.admin.util.Log.USERMGT.error("Error, simple action response is " + objEvent.target.simpleActionResponse);
                    }

                };

                addUsers.prototype.onaddUsersToGroupError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                };

                addUsers.prototype.onaddUsersToGroupInvalid = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };

				/**
				 *	 Refresh the parent list
				 */
                addUsers.prototype.publishRefresh = function() {
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.userMgt.EventID.ADD_ITEM_SUCCESS
                    msg.windowId = this.getWindowId();
                    msg.refresh = true;
                    tibco.admin.PubSub.publish(msg);

                }


            });
}